<?php
include_once("../Dao/db.php");
include_once("../Service/WebClass/report/Remove.php");
Class AdGroup
{
	// 表示形式
	var $reportAxis = "id";
	
	// 開始時間
	var $fromDate;
	// 結束時間
	var $toDate;
	
	// 詳細検索条件表示フラグ
	var $searchDetailHid = "display:none;";
	
	var $searchCol = "name";
	
	var $searchText;
	
	var $searchType = "0";
	
	var $filterCol = "impression";
	
	var $filterValue;
	
	var $filterType = "1";
	
	var $filter2Col = "sponsored_maxbid";
	
	var $filter2Value;
	
	var $filter2Type = "1";
	
	var $filter3Col = "impression";
	
	var $filter3Value;
	
	var $filter3Type = "1";
	
	// 媒体
	var $searchMediaSelect = "0";
	
	// キャンペーン
	var $searchCampaignSelect = "0";
	
	// 同期状態
	var $searchSync = "0";
	
	// 図種類
	var $graphType = "0";
	
	// 指標1
	var $graphCol1 = "impression";
	
	// 指標2
	var $graphCol2 = "impression";
	
	// グラフサイズ
	var $graphSize = "0";
	
	// ビュー
	var $selectView = "1";
	
	// 成果地点
	var $selectPoint = 0;
	
	// データない非表示
	var $hideZero;
	
	// 削除済みも表示
	var $showDeleted;
	
	// 成果地点リスト
	var $cvPointList = "";
	
	// キャンペーンリスト
	var $campaignOptionList = "";
	
	// 媒体リスト
	var $mediaOptionList = "";	
	
	var $tableList = "";
	
	var $errorMsg = "";
	
	var $fromToRowHtml = "";
	
	var $allRowHtml = "";
	
	var $pageLinkHtml = "";
	
	var $nowPageNum = 1;
	
	var $maxpage ;
	
	// 毎ページのレコード数
	var $RECORD_NUMBER_PER_PAGE = 20;
	
	var $isCampaignSelectClick = 0;
	
	var $isMediaSelectClick = 0;
	
	function MyTask()
	{
		// 初期化の場合
		if($_POST["act"] == null)
		{
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();
			// 別画面遷移するの場合
			if($_GET["campaignId"] != null)
			{
				$this->searchCampaignSelect = $_GET["campaignId"];
				$this->fromDate = $_GET["fromDate"];
				$this->toDate = $_GET["toDate"];
				$this->setMediaList($this->searchCampaignSelect);
				$this->searchDetailHid = "display:block;";
			}		
			$this->getTableList($this->nowPageNum);			
		}
		// 検索の場合
		else if($_POST["act"] == "submit")
		{
			$this->iniForm();
			$this->getCvPointOptionList();
			$this->getMediaOptionList();			
			$this->getCampaignOptionList();
			if($this->isCampaignSelectClick == "1")
			{
				$this->setMediaList($this->searchCampaignSelect);			
			}
			$this->getTableList($this->nowPageNum);
		}
		// csvの場合
		else if($_POST["act"] == "csv")
		{
			$this->iniForm();
			$this->getCvPointOptionList();
			$this->getCampaignOptionList();
			if($this->isCampaignSelectClick == "1")
			{
				$this->setMediaList($this->searchCampaignSelect);			
			}
			$this->outputCsv();
		}
		else if($_POST["act"] == "delete")
		{
			$message = removeAdGroup($_POST["adgroupIdList"]);			
			$this->iniForm();
			$this->getCvPointOptionList();
			$this->getMediaOptionList();
			$this->getCampaignOptionList();	
			if($this->isCampaignSelectClick == "1")
			{
				$this->setMediaList($this->searchCampaignSelect);			
			}
			$this->getTableList($this->nowPageNum);
			echo "<script>alert(\"$message\");</script>";			
		}		
	}
	
	// 成果地点マスタデータを取得する	
	function getCvPointOptionList()
	{
		session_start();
		$sql = "select id,name from cvpoint where memberId=".$_SESSION["memberId"];
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			// i=1は「すべて」の対応
			for ($i=1;$i<$rows+1;$i++)
			{
				$data = mysql_fetch_row($result);				
				$this->cvPointList = $this->cvPointList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}			
		}
	}
	
	// 媒体リストを取得する
	function getMediaOptionList()
	{
		$sql = "select id,name from listingmst";
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if($rows >0)
		{
			for($i=0;$i<$rows;$i++)
			{
				$data = mysql_fetch_row($result);
				$this->mediaOptionList = $this->mediaOptionList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}
		}
	}
	
	function getCampaignOptionList()
	{
		session_start();
		$sql = "select camp_ID,name from campaign where campaign.status <> 9 and memberId=".$_SESSION["memberId"];
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			// i=1は「指定なし」の対応
			for ($i=1;$i<$rows+1;$i++)
			{
				$data = mysql_fetch_row($result);				
				$this->campaignOptionList = $this->campaignOptionList."<option id=".$i." value=".$data[0].">".$data[1]."</option>";
			}			
		}
	}
	
	function AdGroup()
	{
		$this->fromDate = date("Y-m-01",time());
		$this->toDate = date("Y-m-d",time());
	}
	
	function iniForm()
	{
		// 表示形式
		$this->reportAxis = $_POST["report_axis"];
		// 媒体
		$this->searchMediaSelect = $_POST["search_media_select"];
		
		// キャンペーン
		if($_POST["isMediaSelectClick"] == "1")
		{
			$this->searchCampaignSelect = "0";			
		}
		else
		{
			$this->searchCampaignSelect = $_POST["search_campaign_select"];
		}		
		
		// 開始日
		$this->fromDate = $_POST["from_date"];
		
		// 結束日
		$this->toDate = $_POST["to_date"];
		
		// 詳細検索条件表示フラグ
		$this->searchDetailHid = $_POST["search_detail_hid"];
		
		$this->searchCol = $_POST["search_col"];
		
		$this->searchText = $_POST["search_text"];
		
		$this->searchType = $_POST["search_type"];
		
		$this->filterCol = $_POST["filter_col"];
		
		$this->filterValue = $_POST["filter_value"];
		
		$this->filterType = $_POST["filter_type"];
		
		$this->filter2Col = $_POST["filter2_col"];
		
		$this->filter2Value = $_POST["filter2_value"];
		
		$this->filter2Type = $_POST["filter2_type"];

		$this->filter3Col = $_POST["filter3_col"];
		
		$this->filter3Value = $_POST["filter3_value"];
		
		$this->filter3Type = $_POST["filter3_type"];
				
		// 同期状態
		$this->searchSync = $_POST["search_sync"];
		
		// 図種類
		$this->graphType = $_POST["graph_type"];
		
		// 指標1
		$this->graphCol1 = $_POST["graph_col1"];
		
		// 指標2
		$this->graphCol2 = $_POST["graph_col2"];
		
		// グラフサイズ
		$this->graphSize = $_POST["graph_size"];
		
		// ビュー
		$this->selectView = $_POST["select_view"];
		
		// 成果地点
		$this->selectPoint = $_POST["select_point"];
		
		// データない非表示
		$this->hideZero = $_POST["hide_zero"];
		
		// 削除済みも表示
		$this->showDeleted = $_POST["show_deleted"];
		
		$this->nowPageNum = $_POST["nowPage"];	
		
		$this->isCampaignSelectClick = $_POST["isCampaignSelectClick"];			
	}
	
	function getSelectSql()
	{
		// 表示形式を判断する
		// 広告グループ別の場合
		if($this->reportAxis == "id")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select campaign.name campaignname,adgroup.adGr_ID adgroupid,adgroup.name name,adgroup.listingType,adgroup.camp_ID,adgroup.sync,adgroup.status,adgroup.maxContentCpc,adgroup.maxCpc, ";
				$sql = $sql."sum(adreport.impression) impression,sum(adreport.clickCnt) clickCnt,100*sum(adreport.clickCnt)/sum(adreport.impression) ctr,sum(adreport.cost)/sum(adreport.clickCnt) cpc,sum(adreport.cost) cost,";
				$sql = $sql."sum(adcvreport.cv) cv,100*sum(adcvreport.cv)/sum(adreport.clickCnt) cvr,sum(adreport.cost)/sum(adcvreport.cv) cpa,1000*sum(adreport.cost)/sum(adreport.impression) cpm,sum(adcvreport.sales)/sum(adreport.cost) roas,sum(adcvreport.sales) sales,";
				$sql = $sql."sum(adcvreport.sales)/sum(adcvreport.cv) salesValue,avg(adcvreport.clickCvSpan) clickCvSpan,sum(adcvreport.directCvCnt) directCvCnt,sum(adcvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(adcvreport.asistCvCnt) asistCvCnt,sum(adcvreport.postCvCnt) postCvCnt ";
				$sql = $sql."from campaign,((adgroup left join adcvreport on adgroup.adGr_ID = adcvreport.adgroup_id  ";
				$sql = $sql."and TO_DAYS('".$this->fromDate."')<=TO_DAYS(adcvreport.date) ";
				// 成果地点の条件を追加する
				// すべて以外の場合
				if($this->selectPoint != "0")
				{
					$sql = $sql."and adcvreport.cvId = ".$_POST["select_point"]." ";
				}
				else
				{
					$sql = $sql."and adcvreport.cvId = -1 ";
				}				
				$sql = $sql."and TO_DAYS(adcvreport.date)<=TO_DAYS('".$this->toDate."')) " ;
				$sql = $sql."left join adreport ";
				$sql = $sql."on adcvreport.date = adreport.date ";
				$sql = $sql."and adcvreport.memberid = adreport.memberId ";	
				$sql = $sql."and adcvreport.listingtype = adreport.listingType ";
				$sql = $sql."and adcvreport.campaign_id = adreport.campaign_Id ";
				$sql = $sql."and adcvreport.adGroup_id = adreport.adGroup_Id) ";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do 
				//$sql = 		"select AdReport.campaignId campaignId,Campaign.name name,Campaign.status status,Campaign.listingType,Campaign.sync,AdReport.cvName, ";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 日別
		else if ($this->reportAxis == "d")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select DATE_FORMAT(adcvreport.date,'%Y%m%d') date,";
				$sql = $sql."sum(adreport.impression) impression,sum(adreport.clickCnt) clickCnt,100*sum(adreport.clickCnt)/sum(adreport.impression) ctr,sum(adreport.cost)/sum(adreport.clickCnt) cpc,sum(adreport.cost) cost,";
				$sql = $sql."sum(adcvreport.cv) cv,100*sum(adcvreport.cv)/sum(adreport.clickCnt) cvr,sum(adreport.cost)/sum(adcvreport.cv) cpa,1000*sum(adreport.cost)/sum(adreport.impression) cpm,sum(adcvreport.sales)/sum(adreport.cost) roas,sum(adcvreport.sales) sales,";
				$sql = $sql."sum(adcvreport.sales)/sum(adcvreport.cv) salesValue,avg(adcvreport.clickCvSpan) clickCvSpan,sum(adcvreport.directCvCnt) directCvCnt,sum(adcvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(adcvreport.asistCvCnt) asistCvCnt,sum(adcvreport.postCvCnt) postCvCnt ";
				$sql = $sql."from (adgroup left join adcvreport on adgroup.adGr_ID = adcvreport.adgroup_id) ";				
				$sql = $sql."left join adreport ";
				$sql = $sql."on adcvreport.date = adreport.date ";
				$sql = $sql."and adcvreport.memberid = adreport.memberId ";	
				$sql = $sql."and adcvreport.listingtype = adreport.listingType ";
				$sql = $sql."and adcvreport.campaign_id = adreport.campaign_Id ";
				$sql = $sql."and adcvreport.adGroup_id = adreport.adGroup_Id ";			
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do 
				//$sql = 		"select DATE_FORMAT(date,'%Y%m%d') date,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select weekly,";
				$sql = $sql."sum(adreport.impression) impression,sum(adreport.clickCnt) clickCnt,100*sum(adreport.clickCnt)/sum(adreport.impression) ctr,sum(adreport.cost)/sum(adreport.clickCnt) cpc,sum(adreport.cost) cost,";
				$sql = $sql."sum(adcvreport.cv) cv,100*sum(adcvreport.cv)/sum(adreport.clickCnt) cvr,sum(adreport.cost)/sum(adcvreport.cv) cpa,1000*sum(adreport.cost)/sum(adreport.impression) cpm,sum(adcvreport.sales)/sum(adreport.cost) roas,sum(adcvreport.sales) sales,";
				$sql = $sql."sum(adcvreport.sales)/sum(adcvreport.cv) salesValue,avg(adcvreport.clickCvSpan) clickCvSpan,sum(adcvreport.directCvCnt) directCvCnt,sum(adcvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(adcvreport.asistCvCnt) asistCvCnt,sum(adcvreport.postCvCnt) postCvCnt ";
				$sql = $sql."from (adgroup left join adcvreport on adgroup.adGr_ID = adcvreport.adgroup_id) ";				
				$sql = $sql."left join adreport ";
				$sql = $sql."on adcvreport.date = adreport.date ";
				$sql = $sql."and adcvreport.memberid = adreport.memberId ";	
				$sql = $sql."and adcvreport.listingtype = adreport.listingType ";
				$sql = $sql."and adcvreport.campaign_id = adreport.campaign_Id ";
				$sql = $sql."and adcvreport.adGroup_id = adreport.adGroup_Id ";			
			}
			// 成果地点別の場合
			else if($this->select_view == "3")
			{
				// to do
				//$sql = 		"select weekly,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{			
			if($this->selectView != "3")
			{
				$sql = 		"select dayOfTheWeek,";
				$sql = $sql."sum(adreport.impression) impression,sum(adreport.clickCnt) clickCnt,100*sum(adreport.clickCnt)/sum(adreport.impression) ctr,sum(adreport.cost)/sum(adreport.clickCnt) cpc,sum(adreport.cost) cost,";
				$sql = $sql."sum(adcvreport.cv) cv,100*sum(adcvreport.cv)/sum(adreport.clickCnt) cvr,sum(adreport.cost)/sum(adcvreport.cv) cpa,1000*sum(adreport.cost)/sum(adreport.impression) cpm,sum(adcvreport.sales)/sum(adreport.cost) roas,sum(adcvreport.sales) sales,";
				$sql = $sql."sum(adcvreport.sales)/sum(adcvreport.cv) salesValue,avg(adcvreport.clickCvSpan) clickCvSpan,sum(adcvreport.directCvCnt) directCvCnt,sum(adcvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(adcvreport.asistCvCnt) asistCvCnt,sum(adcvreport.postCvCnt) postCvCnt ";
				$sql = $sql."from (adgroup left join adcvreport on adgroup.adGr_ID = adcvreport.adgroup_id) ";				
				$sql = $sql."left join adreport ";
				$sql = $sql."on adcvreport.date = adreport.date ";
				$sql = $sql."and adcvreport.memberid = adreport.memberId ";	
				$sql = $sql."and adcvreport.listingtype = adreport.listingType ";
				$sql = $sql."and adcvreport.campaign_id = adreport.campaign_Id ";
				$sql = $sql."and adcvreport.adGroup_id = adreport.adGroup_Id ";			
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
				//$sql = 		"select dayOfTheWeek,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			if($this->selectView != "3")
			{
				$sql = 		"select DATE_FORMAT(adcvreport.date,'%Y-%m') month,";
				$sql = $sql."sum(adreport.impression) impression,sum(adreport.clickCnt) clickCnt,100*sum(adreport.clickCnt)/sum(adreport.impression) ctr,sum(adreport.cost)/sum(adreport.clickCnt) cpc,sum(adreport.cost) cost,";
				$sql = $sql."sum(adcvreport.cv) cv,100*sum(adcvreport.cv)/sum(adreport.clickCnt) cvr,sum(adreport.cost)/sum(adcvreport.cv) cpa,1000*sum(adreport.cost)/sum(adreport.impression) cpm,sum(adcvreport.sales)/sum(adreport.cost) roas,sum(adcvreport.sales) sales,";
				$sql = $sql."sum(adcvreport.sales)/sum(adcvreport.cv) salesValue,avg(adcvreport.clickCvSpan) clickCvSpan,sum(adcvreport.directCvCnt) directCvCnt,sum(adcvreport.indirectCvCnt) indirectCvCnt,";
				$sql = $sql."sum(adcvreport.asistCvCnt) asistCvCnt,sum(adcvreport.postCvCnt) postCvCnt ";
				$sql = $sql."from (adgroup left join adcvreport on adgroup.adGr_ID = adcvreport.adgroup_id) ";				
				$sql = $sql."left join adreport ";
				$sql = $sql."on adcvreport.date = adreport.date ";
				$sql = $sql."and adcvreport.memberid = adreport.memberId ";	
				$sql = $sql."and adcvreport.listingtype = adreport.listingType ";
				$sql = $sql."and adcvreport.campaign_id = adreport.campaign_Id ";
				$sql = $sql."and adcvreport.adGroup_id = adreport.adGroup_Id ";			
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
				//$sql = 		"select DATE_FORMAT(adcvreport.date,'%Y-%m') month,AdReport.cvName cvName,";
				//$sql = $sql."sum(AdReport.cv) cv ";
			}
		}			
		
		return $sql;		
	}
	
	function getLikeSql($text,$type)
	{
		// 全部一致の場合
		if($type == "0")
		{
			return " = '".$text."' ";
		}
		// 部分一致の場合
		if($type == "1")
		{
			return " like binary '%$text%' ";
		}
	}
	
	function getWhereSqlForAdGroup()
	{		
		if($this->searchDetailHid == "display:none")
		{
		}
		// 詳細検索がある場合
		else
		{
			// 広告グループIDの場合
			if($this->searchCol == "id")
			{
				if(trim($this->searchText) != null && trim($this->searchText) != "")
				{
					$sql = $sql."and adgroup.adGr_ID".$this->getLikeSql(trim($this->searchText),$this->searchType)." ";
				}
			}
			// 広告グループ名の場合
			else if($this->searchCol == "name")
			{
				if(trim($this->searchText) != null && trim($this->searchText) != "")
				{
					$sql = $sql."and adgroup.name".$this->getLikeSql(trim($this->searchText),$this->searchType)." ";
				}
			}
			// 媒体の条件を追加する
			// 指定した場合
			if($this->searchMediaSelect != "0")
			{
				$sql = $sql."and adgroup.listingType=".$this->searchMediaSelect." ";
			}
			// 同期状態の条件を追加する
			// 更新待ちの場合
			if($this->searchSync == "2")
			{
				$sql = $sql."and adgroup.sync=2 ";
			}
			// 同期済の場合
			else if($this->searchSync == "1")
			{
				$sql = $sql."and adgroup.sync=1 ";			
			}
			// エラーの場合
			else if($this->searchSync == "3")
			{
				$sql = $sql."and adgroup.sync=3 ";			
			}
			// キャンペーンの条件を追加する
			// 指定の場合
			if($this->searchCampaignSelect != "0")
			{
				$sql = $sql."and adgroup.camp_ID = ".$this->searchCampaignSelect." ";
			}		
			// 入札額の条件を追加する
			if($this->filter2Value !="")
			{
				// スポンサードサーチ入札額の場合
				if($this->filter2Col == "sponsored_maxbid")
				{
					// 以下の場合
					if($this->filter2Type == "2")
					{
						$sql = $sql."and adgroup.maxcpc <=".$this->filter2Value." ";
					}
					// 以上の場合
					else
					{
						$sql = $sql."and adgroup.maxcpc >=".$this->filter2Value." ";
					}
				}
				// コンテンツマッチ入札額の場合
				else
				{
					// 以下の場合
					if($this->filter2Type == "2")
					{
						$sql = $sql."and adgroup.maxContentCpc <=".$this->filter2Value." ";
					}
					// 以上の場合
					else
					{
						$sql = $sql."and adgroup.maxContentCpc >=".$this->filter2Value." ";
					}
				}		
			}			
		}
		// 削除済みも表示の条件を追加する
		// 削除非表示
		if($this->showDeleted != "1")
		{
		$sql = $sql."and adgroup.status <> 9 ";
		}		
		return $sql;
	}
	
	function getWhereSql()
	{
		// 詳細検索条件のフラグを判断する
		// 詳細検索がない場合
		if($this->searchDetailHid == "display:none")
		{
			$sql = "and TO_DAYS('".$this->fromDate."')<=TO_DAYS(adcvreport.date) and TO_DAYS(adcvreport.date)<=TO_DAYS('".$this->toDate."') ";
		}
		// 詳細検索がある場合
		else
		{
			$sql = "and TO_DAYS('".$this->fromDate."')<=TO_DAYS(adcvreport.date) and TO_DAYS(adcvreport.date)<=TO_DAYS('".$this->toDate."') ";
			// 広告グループIDの場合
			if($this->searchCol == "id")
			{
				if(trim($this->searchText) != null && trim($this->searchText) != "")
				{
					$sql = $sql."and adgroup.adGr_ID".$this->getLikeSql(trim($this->searchText),$this->searchType)." ";
				}
			}
			// 広告グループ名の場合
			else if($this->searchCol == "name")
			{
				if(trim($this->searchText) != null && trim($this->searchText) != "")
				{
					$sql = $sql."and adgroup.name".$this->getLikeSql(trim($this->searchText),$this->searchType)." ";
				}
			}
			// 媒体の条件を追加する
			// 指定した場合
			if($this->searchMediaSelect != "0")
			{
				$sql = $sql."and adgroup.listingType=".$this->searchMediaSelect." ";
			}
			// 同期状態の条件を追加する
			// 更新待ちの場合
			if($this->searchSync == "2")
			{
				$sql = $sql."and adgroup.sync=2 ";
			}
			// 同期済の場合
			else if($this->searchSync == "1")
			{
				$sql = $sql."and adgroup.sync=1 ";			
			}
			// エラーの場合
			else if($this->searchSync == "3")
			{
				$sql = $sql."and adgroup.sync=3 ";			
			}
			// キャンペーンの条件を追加する
			// 指定の場合
			if($this->searchCampaignSelect != "0")
			{
				$sql = $sql."and adgroup.camp_ID= ".$this->searchCampaignSelect." ";
			}
			// 入札額の条件を追加する
			if($this->filter2Value !="")
			{
				// スポンサードサーチ入札額の場合
				if($this->filter2Col == "sponsored_maxbid")
				{
					// 以下の場合
					if($this->filter2Type == "2")
					{
						$sql = $sql."and adgroup.maxcpc <=".$this->filter2Value." ";
					}
					// 以上の場合
					else
					{
						$sql = $sql."and adgroup.maxcpc >=".$this->filter2Value." ";
					}
				}
				// コンテンツマッチ入札額の場合
				else
				{
					// 以下の場合
					if($this->filter2Type == "2")
					{
						$sql = $sql."and adgroup.maxContentCpc <=".$this->filter2Value." ";
					}
					// 以上の場合
					else
					{
						$sql = $sql."and adgroup.maxContentCpc >=".$this->filter2Value." ";
					}
				}		
			}
		}
		// 成果地点の条件を追加する
		// すべて以外の場合
		if($this->selectPoint != "0")
		{
			$sql = $sql."and adcvreport.cvId = ".$this->selectPoint." ";
		}
		else
		{
			$sql = $sql."and adcvreport.cvId = -1 ";
		}
		
		// 削除済みも表示の条件を追加する
		// 削除非表示
		if($this->showDeleted != "1")
		{
			$sql = $sql."and adgroup.status <> 9 ";
		}		
		return $sql;
	}	
	
	function getGroupSql()
	{
		// 広告グループ別
		if($this->reportAxis == "id")
		{
			$sql = "group by name,adgroup.adGr_ID ";
		}
		// 日別
		if ($this->reportAxis == "d")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by date,cvName ";
			} 
			else
			{
				$sql = "group by date ";
			}
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by weekly,cvName ";
			}
			else
			{
				$sql = "group by weekly ";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by dayOfTheWeek,cvName";
			}
			else
			{
				$sql = "group by dayOfTheWeek ";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			// 成果地点別の場合
			if($this->selectView == "3")
			{
				$sql = "group by month,cvName ";
			}
			else
			{
				$sql = "group by month ";
			}
		}			
		return $sql;
	}
	
	function getHavingSql()
	{
		// 詳細検索がない場合
		if($this->searchDetailHid == "display:none")
		{
			
		}
		else
		{
			// filter_colとfilter3_colがあるの場合
			if(trim($this->filterValue) != null && trim($this->filterValue) != "" &&
			   trim($this->filter3Value) != null && trim($this->filter3Value) != "")
			{
				// filterTypeが以上の場合
				if($this->filterType == "1")
				{
					$sql = "having (".$this->getHavingFilter($this->filterCol).">=".trim($this->filterValue).") ";
				}
				// filterTypeが以下の場合
				else
				{
					$sql = "having (".$this->getHavingFilter($this->filterCol)."<=".trim($this->filterValue).") ";
				}			
				// filter3Typeが以上の場合
				if($this->filter3Type == "1")
				{
					$sql = $sql."and (".$this->getHavingFilter($this->filter3Col).">=".trim($this->filter3Value).") ";
				}
				// filter3Typeが以下の場合
				else
				{
					$sql = $sql."and (".$this->getHavingFilter($this->filter3Col)."<=".trim($this->filter3Value).") ";
				}
				return $sql;						
			}
			// filter_colとfilter3_colが全部入力しません
			else if((trim($this->filterValue) == null || trim($this->filterValue) == "") &&
			   (trim($this->filter3Value) == null || trim($this->filter3Value) == ""))
			{
				return " ";
			}
			else
			{
				// filter_colの条件を追加する
				if(trim($this->filterValue) != null && trim($this->filterValue) != "")
				{
					// filterTypeが以上の場合
					if($this->filterType == "1")
					{
						$sql = "having (".$this->getHavingFilter($this->filterCol).">=".trim($this->filterValue).") ";
					}
					// filterTypeが以下の場合
					else
					{
						$sql = "having (".$this->getHavingFilter($this->filterCol)."<=".trim($this->filterValue).") ";
					}
					return $sql;							
				}
				// filter3_colの条件を追加する
				else
				{
					// filter3_colの条件を追加する
					if(trim($this->filter3Value) != null && trim($this->filter3Value) != "")
					{
						// filter3Typeが以上の場合
						if($this->filter3Type == "1")
						{
							$sql = "having (".$this->getHavingFilter($this->filter3Col).">=".trim($this->filter3Value).") ";
						}
						// filter3Typeが以下の場合
						else
						{
							$sql = "having (".$this->getHavingFilter($this->filter3Col)."<=".trim($this->filter3Value).") ";
						}
						return $sql;			
					}	
				}					
			}	
		}
	}
	
	function getOrderSql()
	{
		$sql = "";
		// 広告グループ別
		if($this->reportAxis == "id")
		{
			$sql = "order by name ";
		}
		// 日別
		if ($this->reportAxis == "d")
		{
			$sql = "order by date ";
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			$sql = "order by weekly ";
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			$sql = "order by dayOfTheWeek ";
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			$sql = "order by month ";
		}		
		return $sql;
	}
	
	function getTableList($pageNumb)
	{		
		$fromRow = ($pageNumb-1) * $this->RECORD_NUMBER_PER_PAGE;
		$sql = $this->getSelectSql();
		session_start();
		// 広告グループ別の場合
		if($this->reportAxis == "id")
		{
			$sql = $sql."where campaign.camp_ID = adgroup.camp_ID ";
			$sql = $sql."and adgroup.memberId = ".$_SESSION["memberId"]." ";
			$sql = $sql.$this->getWhereSqlForAdGroup();
		}
		else
		{
			$sql = $sql."where adgroup.memberId = ".$_SESSION["memberId"]." ";			
			$sql = $sql.$this->getWhereSql();			
		}
		$sql = $sql.$this->getGroupSql();
		$sql = $sql.$this->getHavingSql();
		$sql = $sql.$this->getOrderSql();			
		$sql = $sql."limit ".$fromRow.",".$this->RECORD_NUMBER_PER_PAGE;
		$totalSql = $this->getSelectSql();
		session_start();
		// グループ別の場合
		if($this->reportAxis == "id")
		{
			$totalSql = $totalSql."where campaign.camp_ID = adgroup.camp_ID ";
			$totalSql = $totalSql."and adgroup.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSqlForAdGroup();
		}
		else
		{
			$totalSql = $totalSql."where adgroup.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSql();			
		}
		$totalSql = $totalSql.$this->getGroupSql();
		$totalSql = $totalSql.$this->getHavingSql();
		$totalSql = $totalSql.$this->getOrderSql();
		$resultL = mysql_query($sql);
		$rowsL = mysql_num_rows($resultL);
		$resultT = mysql_query($totalSql);
		$rowsT = mysql_num_rows($resultT);
		if($rowsL > 0)
		{	
			$fromRowNumber = $fromRow + 1;
			$toRowNumber  = $fromRowNumber + $rowsL -1;
			$this->fromToRowHtml = $fromRowNumber."件-".$toRowNumber."件";
			$this->allRowHtml =  "/".$rowsT."件";
			$this->getPageLinkHtml($rowsT);
			
			// ヘーダを取得する
			$this->tableList = $this->getHeadHtml();
			// 合計値
			$totalImp;
			$totalClick;
			$totalCtr;
			$totalCpc;
			$totalCost;
			$totalCv;
			$totalCvr;
			$totalCpa;
			$totalCpm;
			$totalRoas;
			$totalSales;
			$totalSalesValue;
			$totalClickCv;
			$totalDirect;
			$totalInDirect;
			$totalAsist;
			$totalPost;

			
			// 表示形式を判断する
			// キャンペーン別の場合
			if($this->reportAxis == "id")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["adgroupid"]."</td>";
						// 削除の場合
						if($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_deleted.gif' border='0' title='削除'></td>";
						}
						else 
						{
							// 同期済みの場合
							if($data["sync"] == "1")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_on.gif' border='0' title='同期済'></td>";
							}
							// 非同期の場合
							else if($data["sync"] == "2")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_updating.gif' border='0' title='非同期'></td>";
							}
							// エラーの場合
							else if($data["sync"] == "3")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_error.gif' border='0' title='エラー'></td>";
							}
						}
						if ($data["status"] != "9")
						{
							$this->tableList = $this->tableList."<td><a href='adGroupEdit.php?listingType=".$data["listingType"]."&adGroupId=".$data["adgroupid"]."&campaignId=".$data["camp_ID"]."' target='_blank'>";
							$this->tableList = $this->tableList."<img src='../images/btn_edit.gif' width='16' height='16' border='0'/></a></td>";						
						}
						// 削除の場合
						else 
						{
							$this->tableList = $this->tableList."<td>&nbsp</td>";
						}
						$this->tableList = $this->tableList."<td align=left>".$data["name"]."</td>";
						// 掲載状態を判断する
						// 掲載中
						if($data["status"] == "1")
						{
							$this->tableList = $this->tableList."<td align='center'>On</td>";	
						}
						// 非掲載
						else
						{
							$this->tableList = $this->tableList."<td align='center'>Off</td>";							
						}
						$this->tableList = $this->tableList."<td align='center'>";
						$this->tableList = $this->tableList."<input type=button value=クリエイティブ class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='creative.php?fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"];
						$this->tableList = $this->tableList."&campaignId=".$data["camp_ID"]."&adgroupId=".$data["adgroupid"]."'\"</td>";
						$this->tableList = $this->tableList."<td align=center>";
						$this->tableList = $this->tableList."<input type=button value=キーワード class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='keyword.php?fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"];
						$this->tableList = $this->tableList."&campaignId=".$data["camp_ID"]."&adgroupId=".$data["adgroupid"]."'\"</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["maxCpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["maxContentCpc"])."</td>";
						$this->tableList = $this->tableList."<td align=center>".$data["campaignname"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=center><input type=checkbox name=sel value=".$data["adgroupid"]."></td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td></td><td></td><td></td><td align=center>【合計】</td><td></td><td></td><td></td><td></td><td></td><td></td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td><td></td>";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["adgroupid"]."</td>";
						// 削除の場合
						if($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_deleted.gif' border='0' title='削除'></td>";
						}
						else 
						{
							// 同期済みの場合
							if($data["sync"] == "1")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_on.gif' border='0' title='同期済'></td>";
							}
							// 非同期の場合
							else if($data["sync"] == "2")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_updating.gif' border='0' title='非同期'></td>";
							}
							// エラーの場合
							else if($data["sync"] == "3")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_error.gif' border='0' title='エラー'></td>";
							}
						}
						if ($data["status"] != "9")
						{
							$this->tableList = $this->tableList."<td><a href='adGroupEdit.php?listingType=".$data["listingType"]."&adGroupId=".$data["adgroupid"]."&campaignId=".$data["camp_ID"]."' target='_blank'>";
							$this->tableList = $this->tableList."<img src='../images/btn_edit.gif' width='16' height='16' border='0'/></a></td>";						
						}
						// 削除の場合
						else 
						{
							$this->tableList = $this->tableList."<td>&nbsp</td>";
						}
						$this->tableList = $this->tableList."<td align=left>".$data["name"]."</td>";
						// 掲載状態を判断する
						// 掲載中
						if($data["status"] == "1")
						{
							$this->tableList = $this->tableList."<td align='center'>On</td>";	
						}
						// 非掲載
						else
						{
							$this->tableList = $this->tableList."<td align='center'>Off</td>";							
						}
						$this->tableList = $this->tableList."<td align='center'>";
						$this->tableList = $this->tableList."<input type=button value=クリエイティブ class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='creative.php?fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"];
						$this->tableList = $this->tableList."&campaignId=".$data["camp_ID"]."&adgroupId=".$data["adgroupid"]."'\"</td>";
						$this->tableList = $this->tableList."<td align=center>";
						$this->tableList = $this->tableList."<input type=button value=キーワード class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='keyword.php?fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"];
						$this->tableList = $this->tableList."&campaignId=".$data["camp_ID"]."&adgroupId=".$data["adgroupid"]."'\"</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["maxCpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["maxContentCpc"])."</td>";
						$this->tableList = $this->tableList."<td align=center>".$data["campaignname"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=center><input type=checkbox name=sel value=".$data["adgroupid"]."></td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td></td><td></td><td></td><td align=center>【合計】</td><td></td><td></td><td></td><td></td><td></td><td></td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td><td></td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td><td></td>";
						}
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["adgroupid"]."</td>";
						// 削除の場合
						if($data["status"] == "9")
						{
							$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_deleted.gif' border='0' title='削除'></td>";
						}
						else 
						{
							// 同期済みの場合
							if($data["sync"] == "1")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_on.gif' border='0' title='同期済'></td>";
							}
							// 非同期の場合
							else if($data["sync"] == "2")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_updating.gif' border='0' title='非同期'></td>";
							}
							// エラーの場合
							else if($data["sync"] == "3")
							{
								$this->tableList = $this->tableList."<td align='center'><img src='../images/sync_error.gif' border='0' title='エラー'></td>";
							}
						}
						if ($data["status"] != "9")
						{
							$this->tableList = $this->tableList."<td><a href='adGroupEdit.php?listingType=".$data["listingType"]."&adGroupId=".$data["adgroupid"]."&campaignId=".$data["camp_ID"]."' target='_blank'>";
							$this->tableList = $this->tableList."<img src='../images/btn_edit.gif' width='16' height='16' border='0'/></a></td>";						
						}
						// 削除の場合
						else 
						{
							$this->tableList = $this->tableList."<td>&nbsp</td>";
						}
						$this->tableList = $this->tableList."<td align=left>".$data["name"]."</td>";
						// 掲載状態を判断する
						// 掲載中
						if($data["status"] == "1")
						{
							$this->tableList = $this->tableList."<td align='center'>On</td>";	
						}
						// 非掲載
						else
						{
							$this->tableList = $this->tableList."<td align='center'>Off</td>";							
						}
						$this->tableList = $this->tableList."<td align='center'>";
						$this->tableList = $this->tableList."<input type=button value=クリエイティブ class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='creative.php?fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"];
						$this->tableList = $this->tableList."&campaignId=".$data["camp_ID"]."&adgroupId=".$data["adgroupid"]."'\"</td>";
						$this->tableList = $this->tableList."<td align=center>";
						$this->tableList = $this->tableList."<input type=button value=キーワード class='btn btn_wider'";
						$this->tableList = $this->tableList." onclick=\"javascript:window.location='keyword.php?fromDate=".$this->fromDate."&toDate=".$this->toDate."&listingType=".$data["listingType"];
						$this->tableList = $this->tableList."&campaignId=".$data["camp_ID"]."&adgroupId=".$data["adgroupid"]."'\"</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["maxCpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["maxContentCpc"])."</td>";
						$this->tableList = $this->tableList."<td align=center>".$data["campaignname"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=center><input type=checkbox name=sel value=".$data["adgroupid"]."></td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td></td><td></td><td></td><td align=center>【合計】</td><td></td><td></td><td></td><td></td><td></td><td></td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td><td></td>";
					}
				}						
			}
			// 日別
			else if ($this->reportAxis == "d")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["date"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["date"]."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["date"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}						
			}
			// 週別
			else if ($this->reportAxis == "w")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getWeekDate($data["weekly"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$this->getWeekDate($data["weekly"])."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}	
					}				
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getWeekDate($data["weekly"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
			}
			// 曜日別
			else if ($this->reportAxis == "dow")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getDayOfTheWeekName($data["dayOfTheWeek"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$this->getDayOfTheWeekName($data["dayOfTheWeek"])."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
					}					
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$this->getDayOfTheWeekName($data["dayOfTheWeek"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
			}
			// 月別
			else if ($this->reportAxis == "m")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["month"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["impression"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["ctr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalImp)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalClick)."</td>";
						// ctr
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";						
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalClick/$totalImp,2))."</td>";						
						}
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}
						$this->tableList = $this->tableList."<td align='center'>".$data["month"]."</td>";						
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cost"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpc"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpm"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cpa"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["roas"])."</td></tr>";						
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalImp = $totalImp + $data["impression"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalCost = $totalCost + $data["cost"];
							$totalCv = $totalCv + $data["cv"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCost)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";					
						// cpc
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalClick,2))."</td>";
						}					
						// cpm
						if($totalImp == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(1000*$totalCost/$totalImp,2))."</td>";
						}
						// cpa
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalCost/$totalCv,2))."</td>";
						}
						// roas
						if($totalCost == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCost,2))."</td>";
						}
					}					
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						if($i%2 == "0")
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr3'>";
						}
						else
						{
							$this->tableList = $this->tableList."<tr align='right' class='tr4'>";
						}						
						$this->tableList = $this->tableList."<td align='center'>".$data["month"]."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cv"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["cvr"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["sales"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["salesValue"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["clickCvSpan"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["directCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["indirectCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["asistCvCnt"])."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($data["postCvCnt"])."</td></tr>";
					}
					// 当前頁は最後ページの場合
					if($this->nowPageNum == $this->maxpage)
					{
						for ($i=0;$i<$rowsT;$i++)
						{
							$data = mysql_fetch_array($resultT);
							// 合計値を計算する
							$totalCv = $totalCv + $data["cv"];
							$totalClick = $totalClick + $data["clickCnt"];
							$totalSales = $totalSales + $data["sales"];
							$totalSalesValue = $totalSalesValue + $data["salesValue"];
							$totalClickCv = $totalClickCv + $data["clickCvSpan"];
							$totalDirect = $totalDirect + $data["directCvCnt"];
							$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
							$totalAsist = $totalAsist + $data["asistCvCnt"];
							$totalPost = $totalPost + $data["postCvCnt"];
						}
						// 合計のhtmlを追加する
						$this->tableList = $this->tableList."<tr align=right class=tr_sum><td align=center>【合計】</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalCv)."</td>";
						// cvr
						if($totalClick == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";	
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round(100*$totalCv/$totalClick,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalSales)."</td>";
						// salesValue
						if($totalCv == 0)
						{
							$this->tableList = $this->tableList."<td align=right>-</td>";
						}
						else
						{
							$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalSales/$totalCv,2))."</td>";
						}
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut(round($totalClickCv/$rowsT,2))."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalInDirect)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalAsist)."</td>";
						$this->tableList = $this->tableList."<td align=right>".$this->getNullOutPut($totalPost)."</td>";
					}					
				}
			}						
		}
		// データが内の場合
		else
		{
			$this->tableList = $this->getHeadHtml();
		}
	}
	
	function getPageLinkHtml($totalRowNum)
	{
		for ($i=0;$i < $totalRowNum/$this->RECORD_NUMBER_PER_PAGE;$i++)
		{
			$pageNum = $i+1;
			$this->pageLinkHtml = $this->pageLinkHtml."<td width='10'><a href=\"javascript:document.getElementById('nowPage').value = ".$pageNum.";do_search();\">"."[".$pageNum."]";
			$this->maxpage = $pageNum;
		}
	}
	
	function getHeadHtml()
	{
		// 表示形式を判断する
		// キャンペーン別の場合
		if($this->reportAxis == "id")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>ID</td><td width=12></td><td width=20></td>";
				$html = $html."<td align=left>広告グループ</td>";
				$html = $html."<td align=center>掲載</td>";
				$html = $html."<td></td><td></td>";
				$html = $html."<td align=left>スポンサード<br>サーチ入札額</td>";
				$html = $html."<td align=left>コンテンツ<br>マッチ入札額</td>";
				$html = $html."<td align=left>キャンペーン</td>";				
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td><td width=20 align=center>";
				$html = $html."<input type=checkbox onclick=\"check_all(this.checked, 'sel')\" id=sel_all></td></tr></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>ID</td><td width=12></td><td width=20></td>";
				$html = $html."<td align=left>広告グループ</td>";
				$html = $html."<td align=center>掲載</td>";
				$html = $html."<td></td><td></td>";
				$html = $html."<td align=left>スポンサード<br>サーチ入札額</td>";
				$html = $html."<td align=left>コンテンツ<br>マッチ入札額</td>";
				$html = $html."<td align=left>キャンペーン</td>";				
				$html = $html."<td width=50 align=right>コスト[円]</td>";
				$html = $html."<td width=60 align=right>売上[円]</td>";
				$html = $html."<td width=50 align=right>CPC[円]</td>";
				$html = $html."<td width=50 align=right>CPM[円]</td>";
				$html = $html."<td width=50 align=right>CPA[円]</td>";
				$html = $html."<td width=50 align=right>ROAS[円]</td><td width=20 align=center>";
				$html = $html."<input type=checkbox onclick=\"check_all(this.checked, 'sel')\" id=sel_all></td></tr></tr>";				
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do								
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>ID</td><td width=12></td><td width=20></td>";
				$html = $html."<td align=left>広告グループ</td>";
				$html = $html."<td align=center>掲載</td>";
				$html = $html."<td></td><td></td>";
				$html = $html."<td align=left>スポンサード<br>サーチ入札額</td>";
				$html = $html."<td align=left>コンテンツ<br>マッチ入札額</td>";
				$html = $html."<td align=left>キャンペーン</td>";				
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td><td width=20 align=center>";
				$html = $html."<input type=checkbox onclick=\"check_all(this.checked, 'sel')\" id=sel_all></td></tr></tr>";				
			}						
		}
		// 日別
		else if ($this->reportAxis == "d")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>日付</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>日付</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>日付</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}						
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>週</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td align=center>週</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td align=center>週</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>曜日</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>曜日</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>曜日</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$html = 	  "<td width=40 align=center>年月</td>";
				$html = $html."<td align=right>Imp</td>";
				$html = $html."<td align=right>Click</td>";
				$html = $html."<td align=right>CTR[%]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$html = 	  "<td width=40 align=center>年月</td>";
				$html = $html."<td align=right>コスト[円]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>CPC[円]</td>";
				$html = $html."<td align=right>CPM[円]</td>";
				$html = $html."<td align=right>CPA[円]</td>";
				$html = $html."<td align=right>ROAS[円]</td></tr>";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$html = 	  "<td width=40 align=center>年月</td>";
				$html = $html."<td align=right>CV</td>";
				$html = $html."<td align=right>CVR[%]</td>";
				$html = $html."<td align=right>売上[円]</td>";
				$html = $html."<td align=right>売上単価[円]</td>";
				$html = $html."<td align=center>Click-CV間隔[秒]</td>";
				$html = $html."<td align=right>直接</td>";
				$html = $html."<td align=right>間接</td>";
				$html = $html."<td align=right>アシスト</td>";
				$html = $html."<td align=right>ポスト効果</td></tr>";
			}
		}
		return $html;
	}
	
	function getNullOutPut($value)
	{
		if($value == null || $value == "")
		{
			return "-";
		}
		else 
		{
			return round($value,2);
		}
	}
	
	function getDayOfTheWeekName($dayOfTheWeekId)
	{
		if($dayOfTheWeekId == "0")
		{
			return "日曜日";
		}
		if($dayOfTheWeekId == "1")
		{
			return "月曜日";
		}
		if($dayOfTheWeekId == "2")
		{
			return "火曜日";
		}
		if($dayOfTheWeekId == "3")
		{
			return "水曜日";
		}
		if($dayOfTheWeekId == "4")
		{
			return "木曜日";
		}
		if($dayOfTheWeekId == "5")
		{
			return "金曜日";
		}
		if($dayOfTheWeekId == "6")
		{
			return "土曜日";
		}
	}
	
	function getHavingFilter($filterCol)
	{
		// %の場合対応
		if($filterCol == "ctr")
		{
			$filterColSql = "100*sum(adreport.clickCnt)/sum(adreport.impression)";
		}
		else if($filterCol == "cvr")
		{
			$filterColSql = "100*sum(adcvreport.cv)/sum(adreport.clickCnt)";
		}
		else if($filterCol == "cpa")
		{
			$filterColSql="sum(adreport.cost)/sum(adcvreport.cv)";
		}
		else if($filterCol == "roas")
		{
			$filterColSql="sum(adcvreport.sales)/sum(adreport.cost)";
		}
		else if($filterCol == "cpm")
		{
			$filterColSql = "1000*sum(adreport.cost)/sum(adreport.impression)";
		}
		else if($filterCol == "cpc")
		{
			$filterColSql = "sum(adreport.cost)/sum(adreport.clickCnt)";
		}
		else if($filterCol == "salesValue")
		{
			$filterColSql = "sum(adcvreport.sales)/sum(adcvreport.cv)";
		}
		// sumの場合
		else
		{
			$filterColSql = "sum(".$filterCol.") ";		
		}
		
		return 	$filterColSql;
	}
	
	function getWeekDate($dateTime)
	{
		$weekdate = date("Y-m-d",strtotime($dateTime));
		return $weekdate."~".strval(date("Y-m-d",strtotime($dateTime) + 24*60*60*(6))); 		
	}
	
	function setMediaList($campaignId)
	{
		session_start();
		$sql = "select listingType from campaign where camp_ID=".$campaignId." and MemberID=".$_SESSION["memberId"];			
		$result = mysql_query($sql);
		$rows = mysql_num_rows($result);
		if ($rows > 0)
		{
			$data = mysql_fetch_row($result);
			$this->searchMediaSelect = $data[0];
		}
		else
		{
			$this->searchMediaSelect = "0";
		}
	}

	function outputCsv() 
	{
		// システム時間を取得
		$nowDate = $this->getDbDate(); 
		//$listcsv = $this->getCsvData();
		// ファイル名を定義
		$filename = "report_".$nowDate;
		$filename = trim($filename); 

		header("Content-Disposition: attachment; filename=".$filename.".csv"); 
		header("Content-Type:APPLICATION/csv"); 

		// タイトルを設定
		$title = $this->getCsvHeadText();
		// 内容を設定
		$content = $this->getCsvConentInfo();

		$csv = $title.$content;
		header ("Content-Length: ".(strlen($csv) + 1) );

		//header("Content-Type:text/comma-separated-values"); 
		//echo $csv;
		echo mb_convert_encoding($csv,"SJIS","UTF-8");
		exit();
	}

	function getDbDate() 
	{
		$sql = "select current_date";
		$result = mysql_query($sql);		
		$rows = mysql_num_rows($result);
		if ($rows == 0) 
		{
			return "";
		} 
		else 
		{
			$nowData = mysql_fetch_row($result);
			return $nowData[0];
		}
	}

	function getCsvHeadText()
	{
		// タイトル
		$headText;

		// 表示形式を判断する
		// キャンペーン別の場合
		if($this->reportAxis == "id")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = $headText."ID,広告グループ,掲載,"
					."スポンサード・サーチ入札額,コンテンツ・マッチ入札額,"
					."キャンペーン,Imp,Click,CTR[%],"
					."CPC[円],コスト[円],CV,CVR[%],CPA[円],CPM[円],"
					."ROAS[円],売上[円],売上単価[円],Click-CV間隔[秒],"
					."直接,間接,アシスト,ポスト効果"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = $headText."ID,広告グループ,掲載,"
					."スポンサード・サーチ入札額,コンテンツ・マッチ入札額,"
					."キャンペーン,コスト[円],売上[円],"
					."CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do								
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = $headText."ID,広告グループ,掲載,スポンサード・サーチ入札額,"
					."コンテンツ・マッチ入札額,キャンペーン,"
					."CV,CVR[%],売上[円],"
					."売上単価[円],Click-CV間隔[秒],直接,間接,"
					."アシスト,ポスト効果"."\r\n";	
			}						
		}
		// 日別
		else if ($this->reportAxis == "d")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "日付,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "日付,コスト[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "日付,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}						
		}
		// 週別
		else if ($this->reportAxis == "w")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "週,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "週,コス[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "週,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
		}
		// 曜日別
		else if ($this->reportAxis == "dow")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "曜日,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "曜日,コス[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "曜日,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
		}
		// 月別
		else if ($this->reportAxis == "m")
		{
			// 標準ビューの場合
			if($this->selectView == "1")
			{
				$headText = "年月,Imp,Click,CTR[%],CPC[円],コスト[円],CV[円],"
					."CVR[%],CPA[円],CPM[円],ROAS[円],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				$headText = "年月,コス[円],売上[円],CPC[円],CPM[円],CPA[円],ROAS[円]"."\r\n";
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				$headText = "年月,CV,CVR[%],売上[円],売上単価[円],"
					."Click-CV間隔[秒],直接,間接,アシスト,ポスト効果"."\r\n";
			}
		}
		return $headText;
	}

	function getCsvConentInfo() 
	{
		// CSVのコンテント
		$csvContent;

		$sql = $this->getSelectSql();
		session_start();
		// 広告グループ別の場合
		if($this->reportAxis == "id")
		{
			$sql = $sql."where campaign.camp_ID = adgroup.camp_ID ";
			$sql = $sql."and adgroup.memberId = ".$_SESSION["memberId"]." ";
			$sql = $sql.$this->getWhereSqlForAdGroup();
		}
		else
		{
			$sql = $sql."where adgroup.memberId = ".$_SESSION["memberId"]." ";			
			$sql = $sql.$this->getWhereSql();			
		}
		$sql = $sql.$this->getGroupSql();
		$sql = $sql.$this->getHavingSql();
		$sql = $sql.$this->getOrderSql();			

		$totalSql = $this->getSelectSql();
		session_start();
		// グループ別の場合
		if($this->reportAxis == "id")
		{
			$totalSql = $totalSql."where campaign.camp_ID = adgroup.camp_ID ";
			$totalSql = $totalSql."and adgroup.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSqlForAdGroup();
		}
		else
		{
			$totalSql = $totalSql."where adgroup.memberId = ".$_SESSION["memberId"]." ";
			$totalSql = $totalSql.$this->getWhereSql();			
		}
		$totalSql = $totalSql.$this->getGroupSql();
		$totalSql = $totalSql.$this->getHavingSql();
		$totalSql = $totalSql.$this->getOrderSql();
		$resultL = mysql_query($sql);
		$rowsL = mysql_num_rows($resultL);
		$resultT = mysql_query($totalSql);
		$rowsT = mysql_num_rows($resultT);
		if($rowsL > 0)
		{	
			
			// 合計値
			$totalImp;
			$totalClick;
			$totalCtr;
			$totalCpc;
			$totalCost;
			$totalCv;
			$totalCvr;
			$totalCpa;
			$totalCpm;
			$totalRoas;
			$totalSales;
			$totalSalesValue;
			$totalClickCv;
			$totalDirect;
			$totalInDirect;
			$totalAsist;
			$totalPost;

			
			// 表示形式を判断する
			// キャンペーン別の場合
			if($this->reportAxis == "id")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["adgroupid"].",";
						$csvContent = $csvContent.$data["name"].",";
						// 掲載状態を判断する
						// 掲載中
						if($data["status"] == "1")
						{
							$csvContent = $csvContent."On,";
						}
						// 非掲載
						else
						{
							$csvContent = $csvContent."Off,";
						}
						$csvContent = $csvContent.$this->getNullOutPut($data["maxCpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["maxContentCpc"]).",";
						$csvContent = $csvContent.$data["campaignname"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["adgroupid"].",";
						$csvContent = $csvContent.$data["name"].",";
						// 掲載状態を判断する
						// 掲載中
						if($data["status"] == "1")
						{
							$csvContent = $csvContent."On,";
						}
						// 非掲載
						else
						{
							$csvContent = $csvContent."Off,";
						}
														
						$csvContent = $csvContent.$this->getNullOutPut($data["maxCpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["maxContentCpc"]).",";
						$csvContent = $csvContent.$data["campaignname"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
												$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["adgroupid"].",";
						$csvContent = $csvContent.$data["name"].",";
						// 掲載状態を判断する
						// 掲載中
						if($data["status"] == "1")
						{
							$csvContent = $csvContent."On,";
						}
						// 非掲載
						else
						{
							$csvContent = $csvContent."Off,";
						}
					
						$csvContent = $csvContent.$this->getNullOutPut($data["maxCpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["maxContentCpc"]).",";
						$csvContent = $csvContent.$data["campaignname"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";						
					}
				}						
			}
			// 日別
			else if ($this->reportAxis == "d")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["date"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["date"].",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$csvContent = $csvContent.$data["date"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}						
			}
			// 週別
			else if ($this->reportAxis == "w")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getWeekDate($data["weekly"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getWeekDate($data["weekly"]).",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getWeekDate($data["weekly"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
			}
			// 曜日別
			else if ($this->reportAxis == "dow")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getDayOfTheWeekName($data["dayOfTheWeek"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$this->getDayOfTheWeekName($data["dayOfTheWeek"]).",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
					
						$csvContent = $csvContent.$this->getDayOfTheWeekName($data["dayOfTheWeek"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
			}
			// 月別
			else if ($this->reportAxis == "m")
			{
				// 標準ビューの場合
				if($this->selectView == "1")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["month"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["impression"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["ctr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
				// コスト分析の場合
				else if($this->selectView == "2")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["month"].",";						
						$csvContent = $csvContent.$this->getNullOutPut($data["cost"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpc"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpm"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cpa"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["roas"])."\r\n";						
					}
				}
				// 成果地点別の場合
				else if($this->selectView == "3")
				{
					// to do
				}
				// コンバージョンの場合
				else if($this->selectView == "4")
				{
					// tableリストを作成する
					for ($i=0;$i<$rowsL;$i++)
					{
						$data = mysql_fetch_array($resultL);
						$csvContent = $csvContent.$data["month"].",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cv"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["cvr"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["sales"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["salesValue"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["clickCvSpan"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["directCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["indirectCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["asistCvCnt"]).",";
						$csvContent = $csvContent.$this->getNullOutPut($data["postCvCnt"])."\r\n";
					}
				}
			}
			// 標準ビューの場合
			if($this->selectView == "1") {
				for ($i=0;$i<$rowsT;$i++)
				{

					$data = mysql_fetch_array($resultT);
					// 合計値を計算する
					$totalImp = $totalImp + $data["impression"];
					$totalClick = $totalClick + $data["clickCnt"];
					$totalCost = $totalCost + $data["cost"];
					$totalCv = $totalCv + $data["cv"];
					$totalSales = $totalSales + $data["sales"];
					$totalSalesValue = $totalSalesValue + $data["salesValue"];
					$totalClickCv = $totalClickCv + $data["clickCvSpan"];
					$totalDirect = $totalDirect + $data["directCvCnt"];
					$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
					$totalAsist = $totalAsist + $data["asistCvCnt"];
					$totalPost = $totalPost + $data["postCvCnt"];
				}

				// 合計の内容を追加する
				// キャンペーン別の場合
				if($this->reportAxis == "id") {
					$csvContent = $csvContent.",,,,合計,,";
				} else {
					$csvContent = $csvContent."合計,";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalImp).",".$this->getNullOutPut($totalClick).",";
				if($totalImp == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(100*$totalClick/$totalImp,2)).",";						
				}						
				// cpc
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";	
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalClick,2)).",";
				}					
				$csvContent = $csvContent.$this->getNullOutPut($totalCost).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalCv).",";
				// cvr
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(100*$totalCv/$totalClick,2)).",";
				}
				// cpa
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalCv,2)).",";
				}

				// cpm
				if($totalImp == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(1000*$totalCost/$totalImp,2)).",";
				}
				// roas
				if($totalCost == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCost,2)).",";
				}

				$csvContent = $csvContent.$this->getNullOutPut($totalSales).",";
				// salesValue
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCv,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut(round($totalClickCv/$rowsT,2)).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalInDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalAsist).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalPost)."\r\n";
			}
			// コスト分析の場合
			else if($this->selectView == "2")
			{
				for ($i=0;$i<$rowsT;$i++)
				{
					$data = mysql_fetch_array($resultT);
					// 合計値を計算する
					$totalImp = $totalImp + $data["impression"];
					$totalClick = $totalClick + $data["clickCnt"];
					$totalCost = $totalCost + $data["cost"];
					$totalCv = $totalCv + $data["cv"];
					$totalSales = $totalSales + $data["sales"];
					$totalSalesValue = $totalSalesValue + $data["salesValue"];
					$totalClickCv = $totalClickCv + $data["clickCvSpan"];
					$totalDirect = $totalDirect + $data["directCvCnt"];
					$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
					$totalAsist = $totalAsist + $data["asistCvCnt"];
					$totalPost = $totalPost + $data["postCvCnt"];
				}
				// 合計のhtmlを追加する
				// キャンペーン別の場合
				if($this->reportAxis == "id") {
					$csvContent = $csvContent.",,,,合計,,";
				} else {
					$csvContent = $csvContent."合計,";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalCost).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalSales).",";					
				// cpc
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalClick,2)).",";
				}					
				// cpm
				if($totalImp == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(1000*$totalCost/$totalImp,2)).",";
				}
				// cpa
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalCost/$totalCv,2)).",";
				}
				// roas
				if($totalCost == 0)
				{
					$csvContent = $csvContent."-"."\r\n";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCost,2))."\r\n";
				}
			}
			// 成果地点別の場合
			else if($this->selectView == "3")
			{
				// to do
			}
			// コンバージョンの場合
			else if($this->selectView == "4")
			{
				for ($i=0;$i<$rowsT;$i++)
				{
					$data = mysql_fetch_array($resultT);
					// 合計値を計算する
					$totalCv = $totalCv + $data["cv"];
					$totalClick = $totalClick + $data["clickCnt"];
					$totalSales = $totalSales + $data["sales"];
					$totalSalesValue = $totalSalesValue + $data["salesValue"];
					$totalClickCv = $totalClickCv + $data["clickCvSpan"];
					$totalDirect = $totalDirect + $data["directCvCnt"];
					$totalInDirect = $totalInDirect + $data["indirectCvCnt"];
					$totalAsist = $totalAsist + $data["asistCvCnt"];
					$totalPost = $totalPost + $data["postCvCnt"];
				}
				// 合計のhtmlを追加する
				// キャンペーン別の場合
				if($this->reportAxis == "id") {
					$csvContent = $csvContent.",,,,合計,,";
				} else {
					$csvContent = $csvContent."合計,";
				}
				
				$csvContent = $csvContent.$this->getNullOutPut($totalCv).",";
				// cvr
				if($totalClick == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round(100*$totalCv/$totalClick,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut($totalSales).",";
				// salesValue
				if($totalCv == 0)
				{
					$csvContent = $csvContent."-,";
				}
				else
				{
					$csvContent = $csvContent.$this->getNullOutPut(round($totalSales/$totalCv,2)).",";
				}
				$csvContent = $csvContent.$this->getNullOutPut(round($totalClickCv/$rowsT,2)).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalInDirect).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalAsist).",";
				$csvContent = $csvContent.$this->getNullOutPut($totalPost)."\r\n";
			}
		}
		return $csvContent;
	}
}
?>